/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package util.converter;

import hibernate.dao.CourseDAO;
import hibernate.entity.Courses;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;

/**
 *
 * @author NDH
 */
@ManagedBean
@RequestScoped
public class CourseConverter implements Converter{

    /**
     * Creates a new instance of CenterConverter
     */
    public CourseConverter() {
    }

    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        Courses c = new CourseDAO().readByID(Integer.parseInt(value));
        return c;
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        Courses c = (Courses) value;
        String s = String.valueOf(c.getCourseId());
        
        return s;
    }
}
